package com.actions.componentes;

import com.mapping.Componentes;
import com.mapping.TipoDisp;
import com.opensymphony.xwork2.ActionSupport;
import static com.opensymphony.xwork2.Action.SUCCESS;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;
import javax.persistence.Persistence;
import javax.persistence.Query;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
/**
 *
 * @author Andres
 */
@Namespace(value="/")
@Action(value="verModificarComponente", results={@Result(name="success",location="/GestionComponentes/modificar.jsp")})
public class VerModificarComponenteAction extends ActionSupport{
    private List<TipoDisp> listaTipoComponentes;
    private Componentes comp;
    private String id;
    
    @Override
    public String execute(){
        String consulta = "select td.IDTIPO,td.TIPO from tipo_disp td left join modelo m on (td.idTipo=m.idTipo) where m.idTipo IS NULL";
        EntityManagerFactory emf = Persistence.createEntityManagerFactory("inventarios");
        EntityManager em = emf.createEntityManager();
        EntityTransaction tx = em.getTransaction();
        tx.begin();
        comp = (Componentes) em.getReference(Componentes.class,Integer.parseInt(id));
        Query query =  em.createNativeQuery(consulta,TipoDisp.class);
        listaTipoComponentes = (List<TipoDisp>) query.getResultList();
        tx.commit();
        em.close();
         
         return SUCCESS;
    }
     public List<TipoDisp> getListaTipoComponentes() {
        return listaTipoComponentes;
    }
    
    public void setId(String id) {
        this.id = id;
    }

    public Componentes getComp() {
        return comp;
    }
}
